import { createRouter, createWebHashHistory } from 'vue-router'
import Login from '../views/Login.vue'

import Index from '../views/Index.vue'
import Register from '@/views/Register.vue'
import Appointment from '@/views/appointment.vue'
import Hospital from '@/views/hospital.vue'
//import Setmeal from '@/views/setmeal.vue'
import Setmeal from '@/views/setmeal .vue'
import Confirmorder from '@/views/confirmorder.vue'
import SelectDate from '@/views/SelectDate.vue'
import Appointmentsuccess from '@/views/appointmentsuccess.vue'
import Appointmentlist from '@/views/appointmentlist.vue'
import Personal from '@/views/Personal.vue'

const routes = [
  {
    path: '/',
    name: 'home',
    component: Login
  },
  {
    path: '/login',
    name: 'Login',
    component: Login
  },
  {
    path: '/index',
    name: 'Index',
    component: Index
  },
  {
    path: '/register',
    name: 'Register',
    component: Register
  },
  {
    path: '/appointment',
    name: 'Appointment',
    component: Appointment,

  },
  {
    path: '/hospital',
    name: 'Hospital',
    component: Hospital
  },
  {
    path: '/setmeal',
    name: 'Setmeal',
    component: Setmeal
  },
  // {
  //   path: '/try',
  //   name: 'Try',
  //   component: Try
  // },
  {
    path: '/selectDate',
    name: 'SelectDate',
    component: SelectDate
  },
  {
    path: '/confirmorder',
    name: 'Confirmorder',
    component: Confirmorder
  },
  {
    path: '/appointmentsuccess',
    name: 'Appointmentsuccess',
    component: Appointmentsuccess
  },
  {
    path: '/personal',
    name: 'Personal',
    component: Personal
  },
  {
    path: '/appointmentlist',
    name: 'AppointlistmentList',
    component: Appointmentlist
  },
]

const router = createRouter({
  history: createWebHashHistory(),
  routes
})
// 路由守卫：跳过登录直接进入setmeal页面
router.beforeEach((to, from, next) => {
  if (to.path === '/setmeal') {
    next(); // 直接放行
  } else {
    // 保留原登录逻辑（可选）
    next();
  }
});
export default router
